package com.voilet.interview.rx.operator.filter;

import android.util.Log;

import com.voilet.interview.rx.operator.absOperator;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

/**
 * Created by kan212 on 2019/4/10.
 */

public class firstLastElement implements absOperator {
    @Override
    public void test() {
        // 获取第1个元素
        Observable.just(1, 2, 3, 4, 5)
                .firstElement()
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        Log.d(TAG, "获取到的第一个事件是： " + integer);
                    }
                });
        //结果是1
    }

    @Override
    public void test2() {
        // 获取最后1个元素
        Observable.just(1, 2, 3, 4, 5)
                .lastElement()
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        Log.d(TAG, "获取到的最后1个事件是： " + integer);
                    }
                });
        //结果是5
    }
}
